<?php


namespace app\admin\controller;


use app\admin\business\memberBus;
use think\facade\View;

class Member extends AdminBase
{
    public function index(){
        return View::fetch();
    }

    /**
     * 获取member以及memberInfo的分页信息
     * @return \think\response\Json
     */
    public function getList(){
        $paging = $this->request->param('paging');
        $phone = $this->request->param('phone');
        $end_time = $this->request->param('end_time');
        $start_time = $this->request->param('start_time');
        $member_category = $this->request->param('member_category');
        $status = $this->request->param('status');
        $where = [];
        if($member_category != -1){
            $where['member_category'] = $member_category;
        }
        if($status != -1){
            $where['status'] = $status;
        }

        $memberBus = new memberBus();
        try {
            $result = $memberBus->getMemberListCategory($phone,$start_time,$end_time,$paging,$where);
        }catch (\Exception $exception){
            return show(config('status.error'),$exception->getMessage());
        }
//        if(!empty($where)){
//            try {
//                $result = $memberBus->getMemberListCategory($phone,$start_time,$end_time,$paging,$where);
//            }catch (\Exception $exception){
//                return show(config('status.error'),$exception->getMessage());
//            }
//        }else{
//            try {
//                $result = $memberBus->getMemberList($phone,$start_time,$end_time,$paging);
//            }catch (\Exception $exception){
//                return show(config('status.error'),$exception->getMessage());
//            }
//        }


        return show(config('status.success'),'获取成功',$result);
    }

    /**
     * 获取member分页信息
     * @return \think\response\Json
     */
    public function getListPage(){
        $current_page = $this->request->param('current_page');
        $num = $this->request->param('num');
//        $current_page = 1;
//        $num = 1;
        $memberBus = new memberBus();
        try {
            $result = $memberBus->getMemberPageBus($current_page,$num);
        }catch (\Exception $exception){
            return show(config('status.error'),$exception->getMessage());
        }
//        $result = $memberBus->with('profile')->select();
        return show(config('status.success'),'获取成功',$result);
    }
    public function detail(){
        $id =$this->request->param('id');
        View::assign("id",$id);
        return View::fetch();
    }
    public function getMemberAllInfo(){
        $id = $this->request->param('id');
        $memberBus = new memberBus();
        try {
            $result = $memberBus->getMemberAllInfoBus($id);
        }catch (\Exception $exception){
            return show(config('status.error'),$exception->getMessage());
        }
        return show(config('status.success'),'获取成功',$result);
    }
    public function getMemberAllInfoByMemberId(){
        $id = $this->request->param('id');
        $memberBus = new memberBus();
        try {
            $result = $memberBus->getMemberAllInfoBus($id);
        }catch (\Exception $exception){
            return show(config('status.error'),$exception->getMessage());
        }
        return show(config('status.success'),'获取成功',$result);
    }
    public function changeMemberInfoStatus(){
        $where = $this->request->param("where");
        $data = $this->request->param("data");
        $memberBus = new memberBus();
        try {
            $result = $memberBus->changeMemberInfoStatusBus($where,$data);
        }catch (\Exception $exception){
            return show(config('status.error'),$exception->getMessage());
        }
        return show(config('status.success'),'状态更改成功');
    }

    public function removeMemberById(){
        $id = $this->request->param("id");
        $memberBus = new memberBus();
        try {
            $result = $memberBus->removeMemberByIdBus($id);
        }catch (\Exception $exception){
            return show(config('status.error'),$exception->getMessage());
        }
        return show(config('status.success'),'删除成功',$result);
    }
    public function setMemberGrade(){
        $id = $this->request->param('id');
        View::assign('id',$id);
        return View::fetch();
    }
    public function getMemberInfoOneById(){
        $member_id = $this->request->param('member_id');
        $memberBus = new memberBus();
        try {
            $result = $memberBus->getMemberInfoOneByIdBus($member_id);
        }catch (\Exception $exception){
            return show(config('status.error'),$exception->getMessage());
        }
        return show(config('status.success'),'获取成功',$result);
    }
    public function changeMemberGrade(){
        $member_time = $this->request->param('member_time');
        $member_id = $this->request->param('member_id');
//        dump($member_time);exit();
        $memberBus = new memberBus();
        try {
            $result = $memberBus->changeMemberGradeBus($member_id,$member_time);
        }catch (\Exception $exception){
            return show(config('status.error'),$exception->getMessage());
        }
        return show(config('status.success'),'更改成功',$result);
    }
    //货主企业运力服务商
    public function myLogistics(){
        $id = $this->request->param('id');
        View::assign('id',$id);
        return View::fetch();
    }

    //物流企业的我的货主
    public function myConsignor(){
        $id = $this->request->param('id');
        View::assign('id',$id);
        return View::fetch();
    }
    public function myDetail(){
        $id = $this->request->param('id');
        View::assign('id',$id);
        return View::fetch();
    }
    //获取
    public function getListChildrenPage(){
        $paging = $this->request->param('paging');
        $where = $this->request->param('where');
        $messageBus = new memberBus();
        try {
            $res = $messageBus->getListChildrenPageBus($where,$paging);
        }catch (\Exception $exception){
            return show(config('status.error'),$exception->getMessage());
        }
        return show(config('status.success'),'获取成功',$res);
    }
    //设置显示首页
    public function setCommendFlag(){
        $member_id = $this->request->param('member_id');
        $commend_flag = $this->request->param('commend_flag');
        $where = [
            'member_id'=>$member_id,
        ];
        $data = [
            'commend_flag' => $commend_flag
        ];
        $messageBus = new memberBus();
        try {
            $res = $messageBus->setCommendFlagBus($where,$data);
        }catch (\Exception $exception){
            return show(config('status.error'),$exception->getMessage());
        }
        return show(config('status.success'),'状态更改成功',$res);
    }
    public function removeLogisticsByWhere(){
        $id = $this->request->param('id');
        $where = [
            'id'=>$id
        ];
        $messageBus = new memberBus();
        try {
            $res = $messageBus->removeLogisticsByWhereBus($where);
        }catch (\Exception $exception){
            return show(config('status.error'),$exception->getMessage());
        }
        return show(config('status.success'),'删除成功',$res);
    }
}